Skip to content

feat(node): Add v7 support for vercelAiIntegration#21613

Open
mydea wants to merge 2 commits into
developfrom
fn/vercel-ai-v7
Open

feat(node): Add v7 support for vercelAiIntegration#21613
mydea wants to merge 2 commits into
developfrom
fn/vercel-ai-v7

Conversation

@mydea

@mydea mydea commented Jun 17, 2026

Copy link
Copy Markdown
Member

In the latest beta release of v7 of the ai package, native tracing channel events are now emitted. This PR adds support for this and thus for instrumentation in this package.

For now, this is only implemented in node, but can also be ported to deno/bun.

A big part of this PR was making sure that the v6 tests also run for v7 to make sure this is compatible. It may need some cleanup but tests pass now. The tests are identical for v6 and v7 (just fixed some formatting stuff, moved folder, added a describe.each to run it multiple times), git just could not fully keep up with the changes so it appears bigger than it is.

Supersedes #21584

Comment thread packages/server-utils/src/vercel-ai/vercel-ai-dc-subscriber.ts
Comment thread packages/server-utils/src/vercel-ai/vercel-ai-dc-subscriber.ts
@mydea mydea force-pushed the fn/vercel-ai-v7 branch from ec59e1b to 21822ce Compare June 17, 2026 17:19
Comment thread packages/node/src/integrations/tracing/vercelai/index.ts
@github-actions

github-actions Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 27.45 kB - -
@sentry/browser - with treeshaking flags 25.88 kB - -
@sentry/browser (incl. Tracing) 45.91 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 47.69 kB - -
@sentry/browser (incl. Tracing, Profiling) 50.69 kB - -
@sentry/browser (incl. Tracing, Replay) 85.1 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 74.71 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 89.8 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 102.47 kB - -
@sentry/browser (incl. Feedback) 44.62 kB - -
@sentry/browser (incl. sendFeedback) 32.25 kB - -
@sentry/browser (incl. FeedbackAsync) 37.38 kB - -
@sentry/browser (incl. Metrics) 28.52 kB - -
@sentry/browser (incl. Logs) 28.76 kB - -
@sentry/browser (incl. Metrics & Logs) 29.45 kB - -
@sentry/react 29.25 kB - -
@sentry/react (incl. Tracing) 48.21 kB - -
@sentry/vue 32.58 kB - -
@sentry/vue (incl. Tracing) 47.78 kB - -
@sentry/svelte 27.48 kB - -
CDN Bundle 29.84 kB - -
CDN Bundle (incl. Tracing) 47.83 kB - -
CDN Bundle (incl. Logs, Metrics) 31.39 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 49.15 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 70.7 kB - -
CDN Bundle (incl. Tracing, Replay) 85.18 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 86.46 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 91.03 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.29 kB - -
CDN Bundle - uncompressed 88.8 kB - -
CDN Bundle (incl. Tracing) - uncompressed 144.78 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 93.5 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 148.75 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 218.33 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 263.64 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 267.6 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 277.34 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 281.29 kB - -
@sentry/nextjs (client) 50.61 kB - -
@sentry/sveltekit (client) 46.3 kB - -
@sentry/core/server 75.82 kB - -
@sentry/core/browser 62.95 kB - -
@sentry/node-core 61.59 kB -0.01% -1 B 🔽
@sentry/node 126.28 kB +1.4% +1.74 kB 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 70.05 kB - -
@sentry/node/light 50.53 kB -0.01% -1 B 🔽
@sentry/node - without tracing 74.09 kB -0.01% -1 B 🔽
@sentry/aws-serverless 85.2 kB -0.01% -1 B 🔽
@sentry/cloudflare (withSentry) - minified 172.78 kB - -
@sentry/cloudflare (withSentry) 432.16 kB - -

View base workflow run

@mydea mydea force-pushed the fn/vercel-ai-v7 branch from 21822ce to d6dba4f Compare June 18, 2026 09:01
@mydea mydea marked this pull request as ready for review June 18, 2026 09:17
@mydea mydea requested a review from a team as a code owner June 18, 2026 09:17
@mydea mydea requested review from JPeer264 and andreiborza and removed request for a team June 18, 2026 09:17
@mydea mydea force-pushed the fn/vercel-ai-v7 branch from 0caa954 to 540d331 Compare June 18, 2026 14:18
Comment thread packages/server-utils/src/vercel-ai/vercel-ai-dc-subscriber.ts Outdated
@nicohrubec nicohrubec self-requested a review June 19, 2026 08:23
@mydea mydea force-pushed the fn/vercel-ai-v7 branch from 540d331 to f8e0817 Compare June 19, 2026 08:33
Comment thread packages/server-utils/src/vercel-ai/vercel-ai-dc-subscriber.ts Outdated
const INTEGRATION_NAME = 'VercelAI';

// `@sentry/conventions` does not expose these yet, so we keep the literals here.
const GEN_AI_TOOL_CALL_ID_ATTRIBUTE = 'gen_ai.tool.call.id';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l: We already have an export for this:

export const GEN_AI_TOOL_CALL_ID_ATTRIBUTE = 'gen_ai.tool.call.id';

code: SPAN_STATUS_ERROR,
message: data.error instanceof Error ? data.error.message : 'unknown_error',
});
span.end();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m: According to @logaretm we should not call span.end() in the error channel. See notion doc.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call, will revisit!

if (messages === undefined) {
return {};
}
return { [GEN_AI_INPUT_MESSAGES]: safeStringify(messages) };

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m: While I know truncation is going away soon(tm), we should make sure we pass this through truncation logic today. The helpers are currently not exported from @sentry/core, so I think we should inline them to avoid exposing new api from core that goes way with the next major anyway.

And also once we do that, we should also record the original length of the message via GEN_AI_INPUT_MESSAGES_ORIGINAL_LENGTH_ATTRIBUTE.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm not sure if worth it to add this today? What if we say for v7 we simply have no truncation? 🤔

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fairly straight forward to add and we wouldn't have to document any differences.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we still need truncation until we enable streamGenAiSpans by default, else we'll have users running into dropped spans/transactions again

});
}

function getRecordingOptions(event: Record<string, unknown>): { recordInputs: boolean; recordOutputs: boolean } {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l: Maybe we can reword this away from "recording options" and expand this to also get the enableTruncation option so we can truncate input messages.

@mydea mydea force-pushed the fn/vercel-ai-v7 branch from 7a776ff to 63b6d82 Compare June 19, 2026 12:59

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 63b6d82. Configure here.

code: SPAN_STATUS_ERROR,
message: data.error instanceof Error ? data.error.message : 'unknown_error',
});
},

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failed spans never ended

High Severity

On the diagnostics-channel error path, spans get an error status but are never finished. asyncEnd skips ending when data.error is set, so rejected AI operations leave invoke_agent, generate_content, and tool spans open in traces.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 63b6d82. Configure here.

} catch {
return '[unserializable]';
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v7 channel skips message truncation

Medium Severity

The v7 tracing-channel path records gen AI inputs and outputs via safeStringify with no truncation or GEN_AI_INPUT_MESSAGES_ORIGINAL_LENGTH_ATTRIBUTE, unlike the v6 OTel path that uses getTruncatedJsonString and default enableTruncation.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 63b6d82. Configure here.

Comment on lines +239 to +249
// `callId` → operationId entry.
clearOperationId(data);
const span = data._sentrySpan;
if (!span) {
return;
}
span.setStatus({
code: SPAN_STATUS_ERROR,
message: data.error instanceof Error ? data.error.message : 'unknown_error',
});
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The error handler for the Vercel AI subscriber sets the span status to error but fails to call span.end(), leaving the span open indefinitely.
Severity: HIGH

Suggested Fix

Add a span.end() call within the error handler in vercel-ai-dc-subscriber.ts after the span's status has been set. This will ensure that spans for failed operations are properly closed and exported.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: packages/server-utils/src/vercel-ai/vercel-ai-dc-subscriber.ts#L234-L249

Potential issue: When an AI operation fails, the `error` event handler in the Vercel AI
subscriber is invoked. This handler correctly sets the span's status to error but omits
the necessary `span.end()` call. Subsequently, the `asyncEnd` handler also exits early
because `data.error` is present, preventing it from closing the span. As a result, the
span is never finalized or exported to Sentry. This will cause failed AI operations to
be invisible in Sentry traces and may lead to a memory leak due to unclosed spans
accumulating in memory.

@logaretm

Copy link
Copy Markdown
Member

Should we try using #21641 here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants